﻿using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace NExplorer.Controls
{
	internal sealed class SendToMenuItem : ToolStripMenuItem
	{
		private readonly FileInfo _fileInfo;

		public SendToMenuItem(FileInfo fileInfo)
			: base(Path.GetFileNameWithoutExtension(fileInfo.Name))
		{
			_fileInfo = fileInfo;

			Image = Utilities.GetIcon(fileInfo.FullName, IconSize.Small).ToBitmap();
		}

		protected override void OnClick(EventArgs e)
		{
			StringBuilder sb = new StringBuilder();

			foreach (FileSystemInfo fileSystemInfo in ServiceManager.Explorer.SelectedItems)
			{
				sb.Append("\"").Append(fileSystemInfo.FullName).Append("\" ");
			}

			ProcessStartInfo startInfo = new ProcessStartInfo(_fileInfo.FullName);
			startInfo.Arguments = sb.ToString();

			Process.Start(startInfo);
		}
	}
}
